package com.example.uchain.controller;

import com.example.uchain.demo.Author;
import com.example.uchain.demo.PageBean;
import com.example.uchain.demo.Result;
import com.example.uchain.service.AuthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j//日志用的注解
@Api(tags = "著作人信息")
public class AuthorColltroller {
    @Autowired
    private AuthorService authorService;

//    @GetMapping("/author")
//    @ApiOperation("查看所有著作人信息")
//    public Result findAll() {
//        log.info("查看所有著作人信息");
//        List<Author> goodsList = authorService.findAll();
//        return Result.success(goodsList);
//    }

    @PostMapping("/author")
    @ApiOperation("新增著作人信息")
    public Result AddAuthor(@RequestBody Author author){
        log.info("新增著作人信息: {}",author);
        return Result.success(authorService.AddAuthor(author));
    }

    @DeleteMapping("/author")
    @ApiOperation("根据id删除著作人信息")
    public Result deleteAuthorById(@RequestParam("memberId") Long memberId){
        log.info("根据id删除著作人信息: {}",memberId);
        return  authorService.deleteAuthorById(memberId);
    }

    @PutMapping( "/author")
    @ApiOperation("修改著作人信息")
    public Result updateById(@RequestBody Author author){
        log.info("修改著作人信息: {}", author);
        authorService.updateById(author);
        return Result.success(authorService.findAllById(author.getMemberId()));
    }
    @GetMapping("/author")
    @ApiOperation("根据id查看著作人信息")
    public Result findAll(@RequestParam("memberId") Long memberId) {
        log.info("根据id查看著作人信息");
        Author authorList = authorService.findAllById(memberId);
        return Result.success(authorList);
    }

    @GetMapping("/queryAuthor")
    @ApiOperation("分页查询著权人信息")
    public Result pageForMem(@RequestParam(defaultValue = "1") Integer Page,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             String name,
                             Long memberId ,
                             String phoneNumber,
                             Integer code){

        log.info("分页查询著权人信息 参数:{},{},{},{},{},{}",Page,pageSize,name,memberId,phoneNumber,code);
        PageBean pageBean=authorService.pageForAut(Page,pageSize,name,memberId,phoneNumber,code);
        return Result.success(pageBean);
    }

}
